package com.hgxd.controller;

import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.pojo.Organization;
import com.hgxd.result.Result;

import com.hgxd.service.IOrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 组织、项目表 前端控制器
 * </p>
 *
 * @author fsd
 * @since 2023-10-18
 */
@Api(tags = "组织、项目表")
@RestController
@RequestMapping("/api/organization")
@CrossOrigin
public class OrganizationController {
    @Resource(name = "OrganizationServiceImpl")
    private IOrganizationService organizationService;

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个",notes = "ID")
    @OperationLogAnnotation(operModule = "组织-查询", operType = "查询", operContent = "根据id查询一个")
    public Result<Organization> findOne(@PathVariable Integer id){
        return Result.ok(organizationService.getById(id));
    }

    /**
     * 获取组织树形结构
     * @return
     */
    @GetMapping("/getOrganizationAndEquipment")
    @ApiOperation(value = "获取组织树形结构", notes = "无需传参")
    @OperationLogAnnotation(operModule = "组织-查询", operType = "查询", operContent = "获取组织树形结构")
    public Result<List<Organization>> getOrganizationAndEquipment(){
        return Result.ok(organizationService.getOrganizationForTree());
    }
    /**
     * 仅获取三级组织
     * @return
     */
    @GetMapping("/getOrganizationAndLevel3")
    @ApiOperation(value = "仅获取三级组织", notes = "无需传参")
    @OperationLogAnnotation(operModule = "组织-查询", operType = "查询", operContent = "仅获取三级组织")
    public Result<List<Organization>> getOrganizationAndLevel3(){
        return Result.ok(organizationService.getOrganizationAndLevel3());
    }
//    /**
//     * 不使用递归获取组织树形结构
//     */
//    @GetMapping("/getOrganizationAndEquipment2")
//    @ApiOperation(value = "获取组织树形结构", notes = "无需传参")
//    @OperationLogAnnotation(operModule = "组织-查询", operType = "查询", operContent = "获取组织树形结构")
//    public Result<List<TreeNode>> getOrganizationAndEquipment2(){
//        return Result.ok(organizationService.getOrganizationForTree2());
//    }



//    /**
//     * 获取父级组织
//     *
//     * @return
//     */
//    @ApiOperation(value = "获取父级组织", notes = "无需传参")
//    @OperationLogAnnotation(operModule = "组织管理-查询", operType = "查询", operContent = "查询父级组织")
//    @GetMapping("/getParentOrganization")
//    public Result<List<Organization>> getParentOrganization() {
//        QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("level", 1);
//        return Result.ok(organizationService.list(queryWrapper));
//    }
//
//    /**
//     * 获取子级组织
//     *
//     * @return
//     */
//    @ApiOperation(value = "获取子级组织", notes = "无需传参")
//    @OperationLogAnnotation(operModule = "组织管理-查询", operType = "查询", operContent = "查询子级组织")
//    @GetMapping("/getSonOrganization")
//    public Result<List<Organization>> getSonOrganization() {
//        QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("level", 2);
//        return Result.ok(organizationService.list(queryWrapper));
//    }

    /**
     * 得到所有的配电室数量
     *
     * @return
     */
    @GetMapping("getCountToSwitchroom")
    @ApiOperation(value = "得到所有的配电室数量", notes = "得到所有的配电室数量")
    @OperationLogAnnotation(operModule = "组织-得到所有的配电室数量", operType = "获取", operContent = "得到所有的配电室数量")
    public Result<Integer> getCountToSwitchroom() {
        return Result.ok(organizationService.getCountToSwitchroom());

    }
}
///**
//* 新增
//*/
//@PostMapping("/save")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result insert(@RequestBody Organization organization) {
//        return Result.ok(organizationService.save(organization));
//        }
//
///**
//* 修改
//*/
//@PostMapping("/update")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result update(@RequestBody Organization organization) {
//        return Result.ok(organizationService.updateById(organization));
//        }
//
///**
//* 根据id删除
//*/
//@PostMapping("/delete/{id}")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result delete(@PathVariable Integer id) {
//        return Result.ok(organizationService.removeById(id));
//        }
//
///**
//* 批量删除
//*/
//@PostMapping("/del/batch")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result deleteBatch(@RequestBody List<Integer> ids) {
//        return Result.ok(organizationService.removeByIds(ids));
//        }
//
///**
//* 查询全部
//*/
//@GetMapping("/getAll")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result findAll() {
//        return Result.ok(organizationService.list());
//        }
//

//
///**
//* 分页模糊查询
//*/
//@GetMapping("/get/page")
//@ApiOperation(value = "",notes = "")
//@ApiImplicitParam(name = "" ,value = "")
//public Result findPage(@RequestParam Integer pageNum,
//@RequestParam Integer pageSize) {
//        QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
//        // 倒序查询
//        queryWrapper.orderByDesc("id");
//        return Result.ok(organizationService.page(new Page<>(pageNum, pageSize),queryWrapper));
//        }
//        }

